﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SDK10kWrapper
{
	partial class Camera
	{
        #region ALL CAMERA METHODs
        /// <summary>
        /// CONNECT TO ALL CAMERA.
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Connect to</param>
        /// <returns>TRUE if connect SUCCESS otherwise FALSE</returns>
        public static bool ConnectAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.Connect() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// CONNECT TO ALL CAMERA.
        /// </summary>
        /// <returns>TRUE if connect SUCCESS otherwise FALSE</returns>
        public static bool ConnectAll()
        {
            List<Camera> cams;
            return ConnectAll(out cams);
        }

        /// <summary>
        /// DISCONNECT FROM ALL CAMERA.
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Disconnect from</param>
        /// <returns>TRUE if connect SUCCESS otherwise FALSE</returns>
        public static bool DisconnectAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.Disconnect() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// DISCONNECT FROM ALL CAMERA.
        /// </summary>
        /// <returns>TRUE if connect SUCCESS otherwise FALSE</returns>
        public static bool DisconnectAll()
        {
            List<Camera> cams;
            return DisconnectAll(out cams);
        }

        /// <summary>
        /// PLAY PREVIEW ALL CAMERA (need connect to camera already)
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Play Preview</param>
        /// <param name="lowCPU">Set this true to reduce CPU Usage (Decode I Frame Only)</param>
        /// <returns>TRUE if Play SUCCESS otherwise FALSE</returns>
        public static bool PlayAll(out List<Camera> FailCameraList, bool lowCPU = true)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.Play(lowCPU) == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// PLAY PREVIEW ALL CAMERA (need connect to camera already)
        /// </summary>
        /// <param name="lowCPU">Set this true to reduce CPU Usage (Decode I Frame Only)</param>
        /// <returns>TRUE if Play SUCCESS otherwise FALSE</returns>
        public static bool PlayAll(bool lowCPU = true)
        {
            List<Camera> cams;
            return PlayAll(out cams, lowCPU);
        }

        /// <summary>
        /// PAUSE PREVIEW ALL CAMERA
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Pause Preview</param>
        /// <returns>TRUE if Pause SUCCESS otherwise FALSE</returns>
        public static bool PauseAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.Pause() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// PAUSE PREVIEW ALL CAMERA
        /// </summary>
        /// <returns>TRUE if Pause SUCCESS otherwise FALSE</returns>
        public static bool PauseAll()
        {
            List<Camera> cams;
            return PauseAll(out cams);
        }

        /// <summary>
        /// STOP PREVIEW ALL CAMERA
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Stop Preview</param>
        /// <returns>TRUE if Stop SUCCESS otherwise FALSE</returns>
        public static bool StopAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.Stop() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// STOP PREVIEW ALL CAMERA
        /// </summary>
        /// <returns>TRUE if Stop SUCCESS otherwise FALSE</returns>
        public static bool StopAll()
        {
            List<Camera> cams;
            return StopAll(out cams);
        }

        /// <summary>
        /// RECORD TO FILE BY ALL CAMERA (need connect to camera already)
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Record to File</param>
        /// <param name="NewFolder">Change Record Folder to new Location (Permenantly)</param>
        /// <param name="NewFile">Implement later : Change Record File Name (Permenantly). Now use the caminfo.SavePath instead</param>
        /// <returns>TRUE if Record SUCCESS otherwise FALSE</returns>
        public static bool StartRecordAll(out List<Camera> FailCameraList, string NewFolder = null, string NewFile = null)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (NewFolder != null) cam.SavePath = Path.Combine(NewFolder, Path.GetFileName(cam.SavePath));
                //if (NewFile != null) cam.SavePath = Path.Combine(Path.GetDirectoryName(cam.SavePath), NewFile);
                if (cam.StartRecord() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// RECORD TO FILE BY ALL CAMERA (need connect to camera already)
        /// </summary>
        /// <param name="NewFolder">Change Record Folder to new Location (PERMENANTLY)</param>
        /// <param name="NewFile">Implement later : Change Record File Name (Permenantly). Now use the caminfo.SavePath instead</param>
        /// <returns>TRUE if Record SUCCESS otherwise FALSE</returns>
        public static bool StartRecordAll(string NewFolder = null, string NewFile = null)
        {
            List<Camera> cams;
            return StartRecordAll(out cams, NewFolder, NewFile);
        }

        /// <summary>
        /// STOP RECORD TO FILE FROM ALL CAMERA (need start record already)
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to Record to File</param>
        /// <returns>Return all Files that you success Recording</returns>
        public static Dictionary<Camera, FileInfo> StopRecordAll(out List<Camera> FailCameraList)
        {
            Dictionary<Camera, FileInfo> dict = new Dictionary<Camera, FileInfo>();
            FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                FileInfo fInfo = cam.StopRecord();
                if (fInfo == null) FailCameraList.Add(cam);
                else dict.Add(cam, fInfo);
            }
            return dict;
        }
        /// <summary>
        /// STOP RECORD TO FILE FROM ALL CAMERA (need start record already)
        /// </summary>
        /// <returns>Return all Files that you success Recording</returns>
        public static Dictionary<Camera, FileInfo> StopRecordAll()
        {
            List<Camera> cams;
            return StopRecordAll(out cams);
        }

        /// <summary>
        /// ON SOUND ALL CAMERA
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to ON Sound</param>
        /// <returns>TRUE if On SUCCESS otherwise FALSE</returns>
        public static bool SoundOnAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.SoundON() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// ON SOUND ALL CAMERA
        /// </summary>
        /// <returns>TRUE if On SUCCESS otherwise FALSE</returns>
        public static bool SoundOnAll()
        {
            List<Camera> cams;
            return SoundOnAll(out cams);
        }

        /// <summary>
        /// OFF SOUND ALL CAMERA
        /// </summary>
        /// <param name="FailCameraList">List of Cameras that Fail to OFF sound</param>
        /// <returns>TRUE if Off SUCCESS otherwise FALSE</returns>
        public static bool SoundOffAll(out List<Camera> FailCameraList)
        {
            bool b = true; FailCameraList = new List<Camera>();
            foreach (Camera cam in cams)
            {
                if (cam.SoundOFF() == false) { FailCameraList.Add(cam); b = false; }
            }
            return b;
        }
        /// <summary>
        /// OFF SOUND ALL CAMERA
        /// </summary>
        /// <returns>TRUE if Off SUCCESS otherwise FALSE</returns>
        public static bool SoundOffAll()
        {
            List<Camera> cams;
            return SoundOffAll(out cams);
        }
        #endregion

        #region ONE CAMERA PROPERTIES

        #endregion

        #region ALL CAMERA PROPERTIES
        /// <summary>
        /// CHECK IF ALL CAMERA IS RECORDING OR NOT
        /// </summary>
        public static bool IsRecordingAll
        {
            get
            {
                bool b = true;
                foreach (Camera cam in cams)
                {
                    b = b && cam.IsRecording;
                }
                return b;
            }
        }

        /// <summary>
        /// CHECK IF ALL CAMERA IS PLAYING PREVIEW OR NOT
        /// </summary>
        public static bool IsPlayingAll
        {
            get
            {
                bool b = true;
                foreach (Camera cam in cams)
                {
                    b = b && cam.IsPlaying;
                }
                return b;
            }
        }
        #endregion
	}
}
